home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / intuition / dogadgetmethoda.c < prev    next >
C/C++ Source or Header  |  1996-11-08  |  6KB  |  234 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dogadgetmethoda.c,v 1.2 1996/11/08 11:28:00 aros Exp $
  4.     $Log: dogadgetmethoda.c,v $
  5.     Revision 1.2  1996/11/08 11:28:00  aros
  6.     All OS function use now Amiga types
  7.  
  8.     Moved intuition-driver protos to intuition_intern.h
  9.  
  10.     Revision 1.1  1996/10/25 14:17:54  aros
  11.     New functions
  12.  
  13.  
  14.     Desc: Implementation of DoGadgetMethodA
  15.     Lang: english
  16. */
  17. #include <exec/memory.h>
  18. #include <intuition/classusr.h>
  19. #include <intuition/gadgetclass.h>
  20. #include <intuition/cghooks.h>
  21. #include <clib/alib_protos.h>
  22. #include <clib/exec_protos.h>
  23. #include <clib/graphics_protos.h>
  24. #include <clib/intuition_protos.h>
  25. #include "intuition_intern.h"
  26.  
  27. /*****************************************************************************
  28.  
  29.     NAME */
  30.     #include <intuition/intuition.h>
  31.     #include <clib/intuition_protos.h>
  32.  
  33.     AROS_LH4(IPTR, DoGadgetMethodA,
  34.  
  35. /*  SYNOPSIS */
  36.     AROS_LHA(struct Gadget    *, gad, A0),
  37.     AROS_LHA(struct Window    *, win, A1),
  38.     AROS_LHA(struct Requester *, req, A2),
  39.     AROS_LHA(Msg               , msg, A3),
  40.  
  41. /*  LOCATION */
  42.     struct IntuitionBase *, IntuitionBase, 135, Intuition)
  43.  
  44. /*  FUNCTION
  45.     Invokes a boopsi method on a object with a GadgetInfo derived from
  46.     the supplied window or requester parameter.
  47.  
  48.     INPUTS
  49.     gad - The gadget to work on
  50.     win - The window which contains the gadget or the requester with
  51.         the gadgets.
  52.     req - If the gadget is in a requester, you must specify that one,
  53.         too.
  54.     message - Send this message to the gadget.
  55.  
  56.     RESULT
  57.     The result depends on the contents of the message sent to the
  58.     gadget.
  59.  
  60.     NOTES
  61.  
  62.     EXAMPLE
  63.  
  64.     BUGS
  65.  
  66.     SEE ALSO
  67.  
  68.     INTERNALS
  69.     I have derived from a simular function from ClassAct where I have
  70.     to "fake" the function which is not implemented under OS 2.04.
  71.     There are likely a few differences between this routine and the
  72.     real code, but this gets the job done.
  73.  
  74.     One thing to note, the Amiga Rom routinecauses some form of
  75.     (layer?) locking. I presume the point of the lock is to avoid
  76.     removing the gadget from the window durring a refresh, or to avoid
  77.     resizing the window durring refresh, etc.
  78.  
  79.     This locking is fairly obvious within Workbench itself. When
  80.     refreshing most any boopsi gadget(s) via RefreshGList() and you try
  81.     to drag a Workbench icon you will get stuck in a layer lock.
  82.     Workbench has a deadlock timer and is smart enough to release the
  83.     lock and abort the drag. With this routine below this locking does
  84.     not occur. Some might call it a good thing, however the issue
  85.     should be revisited once more of Intuition has been implemented -
  86.     if it hasn't been already?!. :)
  87.  
  88.     HISTORY
  89.     29-10-95    digulla automatically created from
  90.                 intuition_lib.fd and clib/intuition_protos.h
  91.     25-10-96    calid   submitted the code
  92.  
  93. *****************************************************************************/
  94. {
  95.     AROS_LIBFUNC_INIT
  96.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  97.     IPTR ret = 0;
  98.  
  99.     if (gad) /* OS routines work with NULL objects */
  100.     {
  101.     struct GadgetInfo *gi = (struct GadgetInfo *)AllocMem(sizeof(struct GadgetInfo), MEMF_PUBLIC|MEMF_CLEAR);
  102.  
  103.     if (gi)
  104.     {
  105.         struct Window *tw;
  106.  
  107.         if (req)
  108.         {
  109.         gi->gi_Requester = req;
  110.         tw = req->RWindow;
  111.         }
  112.         else
  113.         {
  114.         gi->gi_Requester = NULL;
  115.         tw = win;
  116.         } /* if */
  117.  
  118.         if (tw)
  119.         {
  120.         /* Initialize the GadgetInfo data. */
  121.         gi->gi_Window          = tw;
  122.         gi->gi_Screen          = tw->WScreen;
  123.         gi->gi_RastPort       = tw->RPort;
  124.         gi->gi_Layer          = tw->WLayer;
  125.         gi->gi_Pens.DetailPen = tw->DetailPen;
  126.         gi->gi_Pens.BlockPen  = tw->BlockPen;
  127.         gi->gi_DrInfo          = GetScreenDrawInfo (gi->gi_Screen);
  128.  
  129.         switch (gad->GadgetType & GTYP_GTYPEMASK)
  130.         {
  131.         case GTYP_SCRGADGET:
  132.             gi->gi_Window     = NULL;
  133.             gi->gi_Domain.Left     = 0;
  134.             gi->gi_Domain.Top     = 0;
  135.             gi->gi_Domain.Width  = tw->WScreen->Width;
  136.             gi->gi_Domain.Height = tw->WScreen->Height;
  137.  
  138.             break;
  139.  
  140.         case GTYP_GZZGADGET:
  141.             gi->gi_Domain.Left     = tw->BorderLeft;
  142.             gi->gi_Domain.Top     = tw->BorderTop;
  143.             gi->gi_Domain.Width  = tw->Width  - tw->BorderLeft - tw->BorderRight;
  144.             gi->gi_Domain.Height = tw->Height - tw->BorderTop  - tw->BorderBottom;
  145.  
  146.             break;
  147.  
  148.         case GTYP_REQGADGET:
  149.             gi->gi_Domain.Left     = req->LeftEdge;
  150.             gi->gi_Domain.Top     = req->TopEdge;
  151.             gi->gi_Domain.Width  = req->Width;
  152.             gi->gi_Domain.Height = req->Height;
  153.  
  154.             break;
  155.  
  156.         default:
  157.             gi->gi_Domain.Left     = 0;
  158.             gi->gi_Domain.Top     = 0;
  159.             gi->gi_Domain.Width  = tw->Width;
  160.             gi->gi_Domain.Height = tw->Height;
  161.  
  162.             break;
  163.  
  164.         } /* switch (gadgettype) */
  165.         } /* if (tw) */
  166.     } /* if (gi) */
  167.  
  168.     switch (msg->MethodID)
  169.     {
  170.     case OM_NEW:
  171.     case OM_SET:
  172.     case OM_NOTIFY:
  173.     case OM_UPDATE:
  174.         ((struct opSet *)msg)->ops_GInfo = gi;
  175.         ret = DoMethodA((Object *)gad, msg);
  176.         break;
  177.  
  178.     case GM_LAYOUT:
  179.         if (gi)
  180.         {
  181.         ((struct gpLayout *)msg)->gpl_GInfo = gi;
  182.  
  183.         ret = DoMethodA((Object *)gad, msg);
  184.         } /* if */
  185.         break;
  186.  
  187.     case GM_RENDER:
  188.         if (gi)
  189.         {
  190.         struct RastPort *rp;
  191.  
  192.         /* Allocate a clone rastport derived from the GadgetInfo
  193.          * whose layer clipping information has been nulled out...
  194.          */
  195.         rp = ObtainGIRPort(gi);
  196.  
  197.         if (rp)
  198.         {
  199.             if (gi->gi_DrInfo)
  200.             {
  201.             SetFont(rp, gi->gi_DrInfo->dri_Font);
  202.             } /* if */
  203.  
  204.             ((struct gpRender *)msg)->gpr_RPort = rp;
  205.             ((struct gpRender *)msg)->gpr_GInfo = gi;
  206.  
  207.             ret = DoMethodA((Object *)gad, msg);
  208.  
  209.             ReleaseGIRPort(rp);
  210.         } /* if */
  211.         } /* if */
  212.         break;
  213.  
  214.     default:
  215.         ((struct gpRender *)msg)->gpr_GInfo = gi;
  216.  
  217.         ret = DoMethodA ((Object *)gad, msg);
  218.         break;
  219.  
  220.     } /* switch */
  221.  
  222.     if (gi)
  223.     {
  224.         if (gi->gi_DrInfo)
  225.         FreeScreenDrawInfo (gi->gi_Screen, gi->gi_DrInfo );
  226.  
  227.         FreeMem ((APTR)gi, sizeof(struct GadgetInfo));
  228.     } /* if */
  229.     } /* if */
  230.  
  231.     return( (ULONG)ret );
  232.     AROS_LIBFUNC_EXIT
  233. } /* DoGadgetMethodA */
  234.